﻿using Microsoft.AspNetCore.Mvc;
using MiniErp.Model.Entities;
using MiniErp.Model.Templates;
using MiniErp.DBService.Service.IService;
using System.IO;
using System.Text.Json;
using Microsoft.AspNetCore.Http;
using System.Threading.Tasks;

namespace MiniErp.App.Controllers
{
    [Route("api")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        private readonly ILoginService _loginService;
        public LoginController(ILoginService loginService)
        {
            _loginService = loginService;
        }

        [Route("Login")]
        [HttpPost]
        public async Task<ActionResult<MessageTemplate<UserInfoEntity>>> Login(int id, string value) => await _loginService.Login(id, value);
        [Route("Register")]
        [HttpPost]
        public async Task<ActionResult<MessageTemplate<int>>> Register(int id, string password, string username, int number, string box)
        {
            var a = Request;
            var userinfo = new UserInfoEntity();
            userinfo.UId = id;
            userinfo.PassWord = password;
            userinfo.UserName = username;
            userinfo.PhoneNumber = number;
            userinfo.MailBox = box;
            userinfo.Rights = 1;
            userinfo.State = true;
            return await _loginService.Register(userinfo);
        }

    }
}
